<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title></title>
	<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
	<style type="text/css">
	   .content .box .form-horizontal .form-group {
		    margin: 10px 0 10px;
		}
		label>* {
		    margin: 0px !important;
		    vertical-align: middle;
		}
		label>span.required {
		    margin-right: 6px !important;
		}
		textarea#hospBakReason {
			display: none;
		}
	</style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>备案药品申请</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#"><i class="active"></i>交易</a></li>
            <li class="active"><a href="#"><i class="active"></i>备案采购</a></li>
            <li class="active"><a href="#"><i class="active"></i>备案申报</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success ">
            <!-- form start -->
            <form role="form" class="form-horizontal" action="bakDrugList.jsp" method="post">
                <div class="box-body">
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">药品编码：</label>
                        <div class="col-sm-4 text-left">
                            ${drug.drugCode}
                        </div>
                        <label class="col-sm-2 text-right">通用名：</label>
                        <div class="col-sm-4 text-left">
                            ${drug.drugName}
                        </div>
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">剂型：</label>
                        <div class="col-sm-4 text-left">
                            ${drug.formName}
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">规格：</label>
                        <div class="col-sm-4 text-left">
                            ${drug.specName}
                        </div>
                        <label class="col-sm-2 text-right">转换系数：</label>
                        <div class="col-sm-4 text-left">
                            ${drug.factor}
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">单位：</label>
                        <div class="col-sm-4 text-left">
                            ${drug.unitName}
                        </div>
                        <label class="col-sm-2 text-right">材质：</label>
                        <div class="col-sm-4 text-left">
                            ${drug.materialName }
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">生产企业：</label>
                        <div class="col-sm-4 text-left">
                            ${drug.compName }
                        </div>
                        <label class="col-sm-2 text-right">批准文号：</label>
                        <div class="col-sm-4 text-left">
                            ${drug.approvalCode }
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>配送企业：</label>
                        <div class="col-sm-4 text-left">
                        	<input  id="compCode"  type="hidden">
                            <input class="form-control" id="compName" placeholder="请选择配送企业" type="text" onclick='editSubComp();' style="background-color:#FFEC8B" ><span class="red" id="delNameFail"></span>	
                        </div>
                        <label class="col-sm-2 text-right"><span class="required">*</span>采购价格（元）：</label>
                        <div class="col-sm-4 text-left">
                            <input class=" form-control" placeholder="请输入采购价格" id="purPrice" type="text" maxlength="18"  style="background-color:#FFEC8B" ><span class="red" id="purPriceFail"></span>
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">备案类型：</label>
                        <div class="col-sm-4 text-left">
                        	<label>
                            	<input type="radio" name="isLongTimePlan" value="0" checked/>&nbsp;临时备案
                            </label>
                            <label>
                            	<input type="radio" name="isLongTimePlan" value="1"/>&nbsp;长期备案
                            </label>
                        </div>
                        <label class="col-sm-2 text-right"><span class="required">*</span>采购数量：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="purAmount" placeholder="请输入采购数量" type="text" maxlength="10" style="background-color:#FFEC8B"><span class="red" id="purAmountFail"></span>
                        </div>                        
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 control-label">备案理由：</label>
                        <div class="col-sm-10">
                            <c:if test="${policy.filingReason != null}">
                                <c:forEach items="${policy.filingReason}" var="reason">
                                    <label>
	                                    <input type="radio" name="reason" value="${reason.key}"/>&nbsp;
	                                    <c:out value="${reason.value}"></c:out>
	                                </label>
                                </c:forEach>
                            </c:if>
                        	<div>
                        		<label>
	                        		<input type="radio" name="reason" id="bakReason" value="${policy.filingReason.size()}"/>&nbsp;
	                        		其他
                        		</label>
                                <textarea class="form-control" name="hospBakReason" id="hospBakReason" placeholder="请输入备案原因(最多512个字符)" maxlength="512"></textarea>
                                <span class="red" id="hospBakReasonFail"></span>
                        	</div>
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 control-label">备注：</label>
                        <div class="col-sm-10">
                            <textarea class="form-control" id="remark" placeholder="备注(最多1024个字符)" maxlength="1024" style="background-color:#FFEC8B"></textarea>
                            <span class="red" id="remarkFail"></span>
                        </div>
                    </div>
                </div>

                <div class="box-footer text-center">
                    <button type="button" class="btn btn-success btn-sm" onclick="submitFiling()">提&nbsp;交</button>
                    <button type="button" class="btn btn-danger btn-sm" onclick="location.href='toAddList.html'">返&nbsp;回</button>
                </div>
            </form>
        </div>
        
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
	    $(function () {
	    	
		    $("input[name='reason']").click(function() {
	        	if ($(this).val() == $("input[name='reason']").length - 1 && $(this).is(":checked")) {
	        		$("textarea#hospBakReason").show();
	        	} else {
	        		$("textarea#hospBakReason").hide();
	        	}
	        });
		    
		    $("input[name='reason']:first").trigger("click");
		    
	    }); 
	    
	    var sumitType = 0; //  0未提交，1已提交
	    
        function submitFiling() {
	    	
           if (sumitType == 1) {
        	   $.alert("备案申报已提交，请勿重置提交！", "warn", function() {
        		   window.location.href = "${ctx}/bakpurchase/toAddList.html";
        	   });
        	   return;
           }
        	
           var compCode = $("#compCode").val();
           if (compCode == "") {
               $.HN.message.alert("请选择配送企业！", "消息", "warn");
               return;
           }
           
           var purPrice = $.trim($("#purPrice").val());
           if (purPrice == "") {
               $.HN.message.alert("请填写采购价格！", "消息", "warn");
               return;
           } else if(/^[0-9]+$/.test(purPrice)){
               purPrice += ".00";
               $("#purPrice").val(purPrice);
           } else if(/^[0-9]+(.[0-9]{1})+$/.test(purPrice)) {
               purPrice += "0";
               $("#purPrice").val(purPrice);
           } else if(!/^[0-9]+(.[0-9]{2})+$/.test(purPrice)) {
               $.HN.message.alert("请填写正确的采购价格！", "消息", "warn");
               return;
           }
           
           var purAmount = $.trim($("#purAmount").val());
           if (purAmount == ""){
               $.HN.message.alert("请填写采购数量！", "消息", "warn");
               return;
           }else if(!/^[0-9]+$/.test(purAmount) || purAmount < 0){
               $.HN.message.alert("采购数量不是正整数！", "消息", "warn");
               return;
           }

           var isLongTimePlan = $("input[name='isLongTimePlan']:checked").val();
           
           var reason = $("input[name='reason']:checked").val();
           var bakReason = $.trim($("input[name='reason']:checked").parent("label").text());
           if (reason == 4) {
        	   bakReason = $("#hospBakReason").val();
               if(bakReason == null || "" == bakReason){
                   $.HN.message.alert("请输入备案理由！", "消息", "warn");
                   return;
               }
           }
           
           var remark = $.trim($("#remark").val());
           
           $.HN.message.confirm('您所提交的备案申请审核通过后方可采购，是否提交上级审核？', '', '').on(function (e) {
               if (e) {
            	 sumitType = 1;
	           	 $.post("submitFiling.html", {
	           		"drugCode" : "${drug.drugCode}",
	           		"delCode" : compCode, 
	           		"purPrice" : purPrice,
	           		"purAmount" : purAmount,
	           		"isLongtimePlan" : isLongTimePlan,
	           		"bakReason" : bakReason,
	           		"remark" : remark
	           	 }, function(result) {
           			if (result.success) {
           				$.HN.message.alert("操作成功！", "消息", "success", function() {
           					window.location.href = "${ctx}/bakpurchase/toAddList.html";
           				});
           			} else {
           				$.HN.message.alert("操作失败！", "消息", "error");
           				sumitType = 0;
           			}
	           	  }, "json")
	            }
	        });
        }
    	
        function editSubComp(){
        	 $.HN.dialog.opendialog(1,"配送企业列表","${ctx}/bidHospplan/toPSCompListJsp.html","800px","400px",operResult);
        }
    	
        function operResult(params){
           	if (params) {
				$("#compCode").val(params.compCode);
				$("#compName").val(params.compName);
			}
       	}
    </script>
</body>
</html>
